﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Ninject;
using Ninject.Web.Common;
using Ninject.Web;
using TeleRad.Repository;
using TeleRad.Services;
using System.Web.Security;
using TeleRad.DBContext;
using System.Security.Principal;

namespace TeleRad.Infrastructure
{
    public class NinjectControllerFactory : DefaultControllerFactory
    {
        private IKernel ninjectKernel;
        public NinjectControllerFactory()
        {
            ninjectKernel = new StandardKernel();
            AddBindings();
        }

        protected override IController GetControllerInstance(RequestContext requestContext,
        Type controllerType)
        {
            return controllerType == null
            ? null
            : (IController)ninjectKernel.Get(controllerType);
        }
        private void AddBindings()
        {
            // put additional bindings here
            //Mock<IProductRepository> mock = new Mock<IProductRepository>();
            //mock.Setup(p => p.Products).Returns(GetPatient().AsQueryable());
            // ninjectKernel.Bind<IPatientRepository>().ToConstant(mock.Object);

            ninjectKernel.Bind<IDbContext>().To<CoreDBContext>().InRequestScope();
            ninjectKernel.Bind(typeof(IRepository<>)).To(typeof(EfRepository<>)).InRequestScope();
            ninjectKernel.Bind<IAccountService>().To<AccountService>().InRequestScope();
            ninjectKernel.Bind<IContentService>().To<ContentService>().InRequestScope();
            ninjectKernel.Bind<IPrincipal>().ToMethod(ctx => HttpContext.Current.User).InRequestScope();
            //ninjectKernel.Inject(Membership.Provider);

            //.InRequestScope()
        }
    }
}